package util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class logwriter {
	private StringBuffer buffer;
	private File logfile;
	private int flag;
	public void console_out(String str)
	{
		System.out.println(str);
	}
	public logwriter(File file)
	{
		this.logfile=file;
		buffer=new StringBuffer();
		flag=0;
	}
	public void info(String str)
	{
		buffer.append("info:\t"+str+"\n");
		buffer.append("\ttime:\t"+System.currentTimeMillis()+"\n\n");
		flag=1;
	}
	public void error(String str)
	{
		buffer.append("error:\t"+str+"\n");
		buffer.append("\ttime:\t"+System.currentTimeMillis()+"\n\n");
		flag=1;
	}
	public void warn(String str)
	{
		buffer.append("warn:\t"+str+"\n");
		buffer.append("\ttime:\t"+System.currentTimeMillis()+"\n\n");
		flag=1;
	}
	public void commit() throws IOException
	{
		if(flag==1)
		{
			BufferedWriter bw=new BufferedWriter(new FileWriter(logfile));
			bw.write(buffer.toString());
			bw.close();
			flag=0;
			buffer=new StringBuffer();
		}
		
		
	}

}
